package com.xinjie.strategy;

import org.junit.Test;

/**
 * @Description: 假设有一个数组，
 * 实现算法：
 * 筛选数组，寻找符合条件的数字
 * @author: xinjie
 * @date: 2020/8/5  15:19
 */
public class StrategyDemo {
	static int[] array = {56, 45, 78, -55, -96, 69, 12, 82, -4, 9, 65, 33, 73, -99, -66, -13};

	/**
	 * 筛选正数
	 *
	 * @param array
	 */
	public void filterPositive(int[] array) {

		for (int a : array) {
			if (a > 0) {
				System.out.println(a);
			}
		}
	}

	@Test
	public void test1() {
		filterPositive(array);
	}


	void filterNegative(int[] array) {
		for (int a : array) {
			if (a < 0) {
				System.out.println(a);
			}
		}
	}

	@Test
	public void test2() {
		filterNegative(array);
	}


//----------------------------------------------------------
//----------------------------------------------------------
//----------------------------------------------------------


	/**
	 * @param array
	 * @param mp
	 */

	public void filter(int[] array, MyPredicate mp) {
		for (int a : array) {
			if (mp.test(a)) {
				System.out.println(a);
			}
		}
	}

	@Test
	public void test5() {
		MyPredicate mp = new FindPositive();
		filter(array, mp);

	}

	@Test
	public void test6() {
		//  1&1 =1  == 奇数
		MyPredicate mp = a -> (a & 1) == 1;
		// 正数
		MyPredicate mp2 = a -> a > 0;
		// fu数
		MyPredicate mp3 = a -> a < 0;

		filter(array , mp3);
		filter(array, a -> a < 0);

	}



}


